﻿<?
	include "config.php";
	include("seguranca.php"); // Inclui o arquivo com o sistema de segurança
    protegePagina(); // Chama a função que protege a página
	if($_SESSION['nivel'] != 'administrador'){ //Se não for ADM desloga o usuário e expulsa da página
		expulsaVisitante();
	}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="../SpryAssets/SpryValidationTextField.js" type="text/javascript"></script>
<script src="../SpryAssets/SpryValidationPassword.js" type="text/javascript"></script>
<link href="../SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css" />
<link href="../SpryAssets/SpryValidationPassword.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="css/bootstrap.css" />
<title>Atualizar Administrador</title>
</head>

<body>
	<?
    if(isset($_GET['action']) && $_GET['action'] == 'atualizar'){
            $id = $_GET['id'];
            $_SESSION['edita'] = $id;
            $consulta = $db->query ("SELECT * FROM administradores WHERE id = '$id'");
            $linha = $consulta->fetch(PDO::FETCH_ASSOC);
    		?>
            <div class="container">
            
            <header class="masthead">
            <h1 class="muted" align="center">Atualizar cadastro de Administrador</h1>
                
            <form id="form1" name="form1" method="post" action="atualizaAdm.php" autocomplete="on">
                
                <span id="sprytextfield1">
                <label for="nome">Nome:</label>
                <input type="text" name="nome" id="nome" value="<? echo "{$linha['nome']}" ?>" />
                <span class="textfieldRequiredMsg">O campo é obrigatório</span></h4></span>
                
                <p><span id="sprytextfield2">
                <label for="usuario">Nome de Usuário:</label>
                <input type="text" name="usuario" id="usuario" value="<? echo "{$linha['usuario']}" ?>"/>
                <br />
                <span class="textfieldRequiredMsg">O campo é obrigatório</span></span>
                </p>
               
                <p><span id="sprypassword1">
                <label for="senha">Senha:</label>
                <input type="password" name="senha" id="senha" value="<? echo "{$linha['senha']}" ?>"/>
                <br />
                <span class="passwordRequiredMsg">O campo é obrigatório</span></span></p>
               
                <p><span id="sprytextfield4">
                <label for="email">Email:</label>
                <input type="text" name="email" id="email" value="<? echo "{$linha['email']}" ?>"/>
                <br />
                <span class="textfieldRequiredMsg">O campo é obrigatório</span><span class="textfieldInvalidFormatMsg">Formato inválido.</span></span></p>
                
                <p><span id="sprytextfield3">
                <label for="fone">Telefone:</label>
                <input type="text" name="fone" id="fone" value="<? echo "{$linha['fone']}" ?>"/>
                <br />
                <span class="textfieldRequiredMsg">O campo é obrigatório</span>
                <span class="textfieldInvalidFormatMsg">Formato inválido.</span></span></p>
                <p>
                
                <input type="submit" name="atualizar" class="btn btn-primary" value="Atualizar"></p>
            </form>
	<? } ?>
</body>

<script type="text/javascript">
        var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1");
        var sprytextfield2 = new Spry.Widget.ValidationTextField("sprytextfield2");
        var sprytextfield4 = new Spry.Widget.ValidationTextField("sprytextfield4", "email");
        var sprypassword1 = new Spry.Widget.ValidationPassword("sprypassword1");
        var sprytextfield3 = new Spry.Widget.ValidationTextField("sprytextfield3", "custom", 
			{useCharacterMasking:true, pattern:"(00) 0000-0000"});
</script>

</html>